package xyz.luhui1hao.collection.collection;

import java.util.*;

/**
 * @ClassName SetMain
 * @Description TODO
 * @Author luhui1hao
 * @Date 2018/9/26 10:15 AM
 * @Version 1.0
 */
public class SetMain {
    public static void main(String[] args){
        System.out.println("HashSet是无序的");
        HashSet hashSet = new HashSet();
        hashSet.add("edf");
        hashSet.add("asd");
        hashSet.add("bfdf");
        hashSet.add("dfdff");
        hashSet.add("zfdf");
        hashSet.add(1);
        hashSet.add(4);
        hashSet.add(2);
        hashSet.add(5);
        hashSet.add(3);

        for(Iterator iterator = hashSet.iterator(); iterator.hasNext();){
            System.out.println(iterator.next());
        }

        System.out.println("---------------------");

        System.out.println("LinkedHashSet是按照添加顺序来排序的");
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        linkedHashSet.add("edf");
        linkedHashSet.add("asd");
        linkedHashSet.add("bfdf");
        linkedHashSet.add("dfdff");
        linkedHashSet.add("zfdf");
        linkedHashSet.add(1);
        linkedHashSet.add(4);
        linkedHashSet.add(2);
        linkedHashSet.add(5);
        linkedHashSet.add(3);

        for(Iterator iterator = linkedHashSet.iterator(); iterator.hasNext();){
            System.out.println(iterator.next());
        }

        System.out.println("---------------------");

        System.out.println("TreeSet是确保元素处于排序状态");
        TreeSet treeSet = new TreeSet();
//        treeSet.add("edf");
//        treeSet.add("asd");
//        treeSet.add("bfdf");
//        treeSet.add("dfdff");
//        treeSet.add("zfdf");
        treeSet.add(1);
        treeSet.add(4);
        treeSet.add(2);
        treeSet.add(5);
        treeSet.add(3);

        for(Iterator iterator = treeSet.iterator(); iterator.hasNext();){
            System.out.println(iterator.next());
        }
    }
}
